package com.zxmclasslibrarie.db;

import java.util.HashMap;

import com.android.email.provider.DBHelper;

import android.content.ContentProvider;
import android.content.ContentUris;
import android.content.ContentValues;
import android.content.UriMatcher;
import android.database.Cursor;
import android.database.DatabaseUtils;
import android.database.sqlite.SQLiteQueryBuilder;
import android.net.Uri;
import android.text.TextUtils;

public abstract class BaseContentProvider extends ContentProvider {

    static UriMatcher mUriMatcher = new UriMatcher(UriMatcher.NO_MATCH);

    private DBHelper mOpenHelper;

    @Override
    public boolean onCreate() {
        mOpenHelper = new DBHelper(getContext());
        return true;
    }

    @Override
    public Cursor query(Uri uri, String[] projection, String selection,
            String[] selectionArgs, String sortOrder) {
        // TODO Auto-generated method stub
        return null;
    }

    @Override
    public String getType(Uri uri) {
        // TODO Auto-generated method stub
        return null;
    }

    @Override
    public Uri insert(Uri uri, ContentValues values) {
        // TODO Auto-generated method stub
        return null;
    }

    @Override
    public int delete(Uri uri, String selection, String[] selectionArgs) {
        // TODO Auto-generated method stub
        return 0;
    }

    @Override
    public int update(Uri uri, ContentValues values, String selection,
            String[] selectionArgs) {
        // TODO Auto-generated method stub
        return 0;
    }

    @SuppressWarnings("unused")
    private String createIDWhere(String _id, Uri uri, String where) {
        return where = DatabaseUtils.concatenateWhere(
                _id + " = " + ContentUris.parseId(uri), where);
    }

    /**
     * 
     * @param qb
     * @param uri
     * @param _id
     * @param selectionArgs
     * @return
     */
    @SuppressWarnings("unused")
    private String[] appendIDSelectionArgs(SQLiteQueryBuilder qb, Uri uri,
            String _id, String[] selectionArgs) {
        qb.appendWhere(_id + "=?");
        return selectionArgs = DatabaseUtils.appendSelectionArgs(selectionArgs,
                new String[] { uri.getLastPathSegment() });
    }

    /**
     * 
     * @param qb
     * @param projectionMap
     * @param tableName
     * @param defaultOrder
     * @param sortOrder
     * @return
     */
    @SuppressWarnings("unused")
    private String setQueryProperties(SQLiteQueryBuilder qb,
            HashMap<String, String> projectionMap, String tableName,
            String defaultOrder, String sortOrder) {
        String orderBy = null;
        qb.setTables(tableName);
        qb.setProjectionMap(projectionMap);
        if (TextUtils.isEmpty(sortOrder)) {
            orderBy = defaultOrder;
        } else {
            orderBy = sortOrder;
        }
        return orderBy;
    }
}
